package sjtu.ist.warehouse4ws.service;

import java.util.ArrayList;
import java.util.List;

import sjtu.ist.warehouse4ws.dao.FunctionpointDao;
import sjtu.ist.warehouse4ws.dao.cust.CustFunctionpointDao;
import sjtu.ist.warehouse4ws.model.CustFunctionpoint;
import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;


public class FunctionpointServiceImpl implements FunctionpointService{
	private FunctionpointDao functionpointDao;
	private CustFunctionpointDao custFunctionpointDao;
	
	public void setFunctionpointDao(FunctionpointDao functionpointDao) {
		this.functionpointDao = functionpointDao;
	}

	public void setCustFunctionpointDao(CustFunctionpointDao custFunctionpointDao) {
		this.custFunctionpointDao = custFunctionpointDao;
	}

	@Override
	public List<Functionpoint> getFunctionpointList(String processid) {
		// TODO Auto-generated method stub
		return (List<Functionpoint>)functionpointDao.findAllFunctionpoints(processid);
	}

	@Override
	public List<Functionpoint> getFunctionpointList() {
		// TODO Auto-generated method stub
		return (List<Functionpoint>)functionpointDao.findAllFunctionpoints();
	}

	@Override
	public void saveFunctionpoint(Functionpoint functionpoint,int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			functionpointDao.savaFunctionpoint(functionpoint);
		}else{
			
		}
	}

	@Override
	public List<Functionpoint> getFunctionPoint(String id) {
		// TODO Auto-generated method stub
		return (List<Functionpoint>)functionpointDao.getFunctionPoint(id);
	}

	@Override
	public List<Functionpoint> getFunctionpointlistbyGroupId(Integer groupId) {
		// TODO Auto-generated method stub
		return functionpointDao.findAllFunctionpointsbyGroupId(groupId);
	}

	@Override
	public List<Functionpoint> getFunctionpointListByUid(String uid) {
		// TODO Auto-generated method stub
		return functionpointDao.findByUid(uid);
	}
	
	@Override
	public List<Functionpoint> getFunctionpointListByGroupAndVersion(String groupId,String versionId,int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			return functionpointDao.findByGroupAndVersion(groupId,versionId);
		}else{
			List<Functionpoint> list=new ArrayList<Functionpoint>();
			List<CustFunctionpoint> clist=custFunctionpointDao.findByGroupAndVersion(groupId,versionId);
			for(CustFunctionpoint cf : clist){
				Functionpoint f=new Functionpoint();
				PropertyHelper.copyProperties(cf, f);
				list.add(f);
			}
			return list;
		}
	}


}
